import "../../../just/libafl-qemu-libpng.just"

FUZZER_NAME := ""
FUZZER_SINGLE := BUILD_DIR / "tmin_single_core" + FUZZER_EXTENSION
FUZZER_MULTI := BUILD_DIR / "tmin_multi_core" + FUZZER_EXTENSION
HARNESS := TARGET_DIR / ("libpng-harness-" + PROFILE)

[unix]
build:
    cargo build \
      --profile {{ PROFILE }} \
      --features {{ ARCH }} \
      --target-dir {{ TARGET_DIR }}

[unix]
harness: libpng
    #!/bin/bash

    source {{ DOTENV }}

    $CROSS_CXX \
        ./harness.cc \
        $CROSS_CFLAGS \
        "{{TARGET_DIR}}/build-png/.libs/libpng16.a" \
        "{{TARGET_DIR}}/build-zlib/libz.a" \
        -I"{{DEPS_DIR}}/libpng-1.6.37" \
        -I"{{TARGET_DIR}}/build-png" \
        -I"{{TARGET_DIR}}/build-zlib/zlib/lib" \
        -L"{{TARGET_DIR}}/build-zlib/zlib/lib" \
        -o"{{ HARNESS }}" \
        -lm -static

[unix]
run_single: build harness
    {{ FUZZER_SINGLE }} \
        --output ./output \
        --input ./corpus \
        -- {{ HARNESS }}

[unix]
run_multi: build harness
    {{ FUZZER_MULTI }} \
        --output ./output \
        --input ./corpus \
        --cores 0 \
        -- {{ HARNESS }}

[unix]
test:
    ARCH=x86_64 just run_single
    ARCH=x86_64 just run_multi
    ARCH=arm just run_single
    ARCH=arm just run_multi

[unix]
clean:
    cargo clean
